package com.example.devicemanage.controller;
//用户业务控制器，用于接收Http请求并进行转发处理

import com.example.devicemanage.entity.User;
import com.example.devicemanage.service.inter.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(path = "/userlogin", method = RequestMethod.GET)
        //获取请求参数方式3,直接使用原生的HttpServletRequest
    String login(HttpServletRequest httpServletRequest){
        String  uid = httpServletRequest.getParameter("uid");
        String uname = httpServletRequest.getParameter("uname");
          int id=Integer.valueOf(uid);
        User user = new User();
        user.setUid(id);
        user.setUname(uname);

        //调用service层验证数据
        boolean flag = userService.login(user);

        if(flag == true){ //登录成功
//            //设置域对象
//            //request域
//            httpServletRequest.setAttribute("str", userId);
//            //session域
//            httpServletRequest.getSession().setAttribute("str", userId);
//            //context域
//            httpServletRequest.getServletContext().setAttribute("str", userId);
            System.out.println("ys&&zbb");
            //转发到index.jsp
            return "index";
        }

        httpServletRequest.setAttribute("str", "登录失败");
        //登录失败返回到login.jsp
        return "index";
    }









}
